package com.samsungimaging.asphodel.multimedia;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.view.SurfaceHolder;
import com.samsung.app.Logger;

public class FFmpegJNI
{
  public static final String ARG_VIDEO_STREAMING_FLUSH = "ffplay flush";
  public static final String ARG_VIDEO_STREAMING_QUIT = "ffplay quit";
  public static final String ARG_VIDEO_STREAMING_TOGGLE_PAUSE = "ffplay toggle_pause";
  private static final String DELIMITER = " ";
  private static final int FFMPEG_ARGB = 27;
  private static final int FFMPEG_RGB565LE = 44;
  public static final int SCREEN_TYPE_PHONE_LAND_CAMERA_LAND = 2;
  public static final int SCREEN_TYPE_PHONE_LAND_CAMERA_PORT = 3;
  public static final int SCREEN_TYPE_PHONE_PORT_CAMERA_LAND = 0;
  public static final int SCREEN_TYPE_PHONE_PORT_CAMERA_PORT = 1;
  private static final String TAG = "[FFmpegJNI]";
  private static int m_argc;
  private static String[] m_argv;
  private static Thread m_ffmpegMainThread;
  private static FFmpegPicture[] m_ffmpegPicture;
  private static FFmpegScreen m_ffmpegScreen;
  private static int m_frameCount;
  private static int m_pictureHeigtht;
  private static int m_pictureQueueLen;
  private static int m_pictureWidth;
  private static boolean m_run = false;

  static
  {
    m_argc = 0;
    m_argv = null;
    m_ffmpegMainThread = null;
    m_ffmpegScreen = null;
    m_frameCount = 0;
    m_pictureQueueLen = 0;
    m_pictureWidth = 0;
    m_pictureHeigtht = 0;
    m_ffmpegPicture = null;
  }

  public static int construct(Bitmap paramBitmap1, Bitmap paramBitmap2, int[][] paramArrayOfInt1, int[][] paramArrayOfInt2, int paramInt1, int paramInt2)
  {
    System.loadLibrary("ffplay-jni");
    m_ffmpegScreen = new FFmpegScreen(paramBitmap1, paramBitmap2, paramArrayOfInt1, paramArrayOfInt2, paramInt1, paramInt2);
    m_run = true;
    return 0;
  }

  public static int destruct()
  {
    m_run = false;
    return 0;
  }

  private static native int ffplayMain(int paramInt, String[] paramArrayOfString);

  private static native int ffplaySDL(int paramInt, String[] paramArrayOfString);

  private static int onDisplay(int paramInt)
  {
    m_ffmpegScreen.drawScreen(onGetPicture(paramInt));
    m_frameCount = 1 + m_frameCount;
    return 0;
  }

  /** @deprecated */
  private static Bitmap onGetPicture(int paramInt)
  {
      if (paramInt < m_pictureQueueLen)
      {
        return m_ffmpegPicture[paramInt].getPicture();
      }
      return null;
  }

  private static int onInitPictureQueue(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    Logger.i("[FFmpegJNI]", "picture queue len : " + paramInt1);
    Logger.i("[FFmpegJNI]", "picture width : " + paramInt2);
    Logger.i("[FFmpegJNI]", "picture height : " + paramInt3);
    Logger.i("[FFmpegJNI]", "picture type : " + paramInt4);
    m_pictureQueueLen = paramInt1;
    m_pictureWidth = paramInt2;
    m_pictureHeigtht = paramInt3;
    Bitmap.Config localConfig = null;
    if (paramInt4 == 27)
    {
      Logger.i("[FFmpegJNI]", "RGB Type : ARGB8888");
      localConfig = Bitmap.Config.ARGB_8888;
      m_ffmpegPicture = new FFmpegPicture[m_pictureQueueLen];
    }
    else if (paramInt4 == 44)
    {
      Logger.i("[FFmpegJNI]", "RGB Type : RGB565");
      localConfig = Bitmap.Config.RGB_565;
    }
    else{
    	Logger.e("[FFmpegJNI]", "Unknown RGB Type!");
    	return -1;
    }
    for (int j = 0;j<m_pictureQueueLen ; j++)
    {
      m_ffmpegPicture[j] = new FFmpegPicture(m_pictureWidth, m_pictureHeigtht, localConfig);
    }
    return 0;
  }

  public static int request(Command paramCommand, int paramInt1, int paramInt2)
  {
    int i;
    if (!m_run)
    {
      Logger.e("[FFmpegJNI]", "You should call construct() function first!");
      return  -1;
    }

      switch (paramCommand.ordinal())
      {
  
      case 8:
        Logger.i("[FFmpegJNI]", "Command : " + paramCommand.toString());
        m_ffmpegScreen.changeScreenConfig(paramInt1, paramInt2);
        i = 0;
        break;
      case 9:
        i = m_frameCount;
        break;
      default:
          Logger.e("[FFmpegJNI]", "Unknown Command!");
          i = -1;
          break;
      }
  
    return i;
  }

  public static int request(Command paramCommand, SurfaceHolder paramSurfaceHolder)
  {
    int i;
    if (!m_run)
    {
      Logger.e("[FFmpegJNI]", "You should call construct() function first!");
      return -1;
    }
      switch (paramCommand.ordinal())
      {
    
      case 5:
    	  Logger.i("[FFmpegJNI]", "Command : " + paramCommand.toString());
          m_ffmpegScreen.configureSurface(paramCommand, paramSurfaceHolder);
          i = 0;
          break;
      case 6:
    	  Logger.i("[FFmpegJNI]", "Command : " + paramCommand.toString());
          m_ffmpegScreen.configureSurface(paramCommand, paramSurfaceHolder);
          i = 0;
          break;
      case 7:
    	  Logger.i("[FFmpegJNI]", "Command : " + paramCommand.toString());
          m_ffmpegScreen.configureSurface(paramCommand, paramSurfaceHolder);
          i = 0;
          break;
      default:
          Logger.e("[FFmpegJNI]", "Unknown Command!");
          i = -1;
          break;
      }
      return i;
    }


  public static int request(Command paramCommand, String paramString)
  {
    int m;
    if (!m_run)
    {
      Logger.e("[FFmpegJNI]", "You should call construct() function first!");
      m = -1;
      label17: return m;
    }
    m_argv = paramString.split(" ");
    m_argc = m_argv.length;
    for (int i = 0; ; i++)
    {
      if (i >= m_argc)
        Logger.i("[FFmpegJNI]", "m_argc : " + m_argc);
      switch (paramCommand.ordinal())
      {
      default:
        Logger.e("[FFmpegJNI]", "Unknown Command!");
        m = -1;
        break label17;
        Logger.i("[FFmpegJNI]", "m_argv[" + i + "] : " + m_argv[i]);
      case 1:
      case 2:
      case 3:
      case 4:
      }
    }
    Logger.i("[FFmpegJNI]", "Command : " + paramCommand.toString());
    if (m_ffmpegMainThread == null)
    {
      m_ffmpegMainThread = new Thread(new Runnable()
      {
        public void run()
        {
          FFmpegJNI.ffplaySDL(FFmpegJNI.m_argc, FFmpegJNI.m_argv);

          FFmpegJNI.m_run = false;
        }
      });
      m_ffmpegMainThread.start();
    }
    while (true)
    {
      m = 0;
      break;
      Logger.i("[FFmpegJNI]", "Video Streaming already started!");
      m = -1;
      break;
      Logger.i("[FFmpegJNI]", "Command : " + paramCommand.toString());
      ffplaySDL(m_argc, m_argv);
      if (paramCommand != Command.VIDEO_STREAMING_QUIT)
        continue;
      int j = 0;
      Logger.i("[FFmpegJNI]", "wait for termination,...");
      try
      {
        Thread.sleep(100L);
        if (!m_run)
          continue;
        int k = j + 1;
        if (j > 30)
          continue;
        j = k;
      }
      catch (InterruptedException localInterruptedException)
      {
        while (true)
          localInterruptedException.printStackTrace();
      }
    }
  }

  public static enum Command
  {

    	 VIDEO_STREAMING_FLUSH("VIDEO_STREAMING_FLUSH", 2),
    	 VIDEO_STREAMING_QUIT("VIDEO_STREAMING_QUIT", 3),
    	 SURFACE_CREATED("SURFACE_CREATED", 4),
    	 SURFACE_CHANGED("SURFACE_CHANGED", 5),
    	 SURFACE_DESTROYED("SURFACE_DESTROYED", 6),
    	 SCREEN_CONFIG_CHANGE("SCREEN_CONFIG_CHANGE", 7),
    	 FRAME_COUNT_GET("FRAME_COUNT_GET", 8),
    	 VIDEO_STREAMING_START,
    	 VIDEO_STREAMING_TOGGLE_PAUSE;
    	 
    	 
    	 private  String name;
     	private  int value;
     	 Command(String name,int value){
     		this.name = name;
     		this.value = value;
     	}
     	 private Command() {
		
		}
     	 static{
      Command[] arrayOfCommand = new Command[9];

      arrayOfCommand[0] = VIDEO_STREAMING_START;
      arrayOfCommand[1] = VIDEO_STREAMING_TOGGLE_PAUSE;
      arrayOfCommand[2] = VIDEO_STREAMING_FLUSH;
      arrayOfCommand[3] = VIDEO_STREAMING_QUIT;
      arrayOfCommand[4] = SURFACE_CREATED;
      arrayOfCommand[5] = SURFACE_CHANGED;
      arrayOfCommand[6] = SURFACE_DESTROYED;
      arrayOfCommand[7] = SCREEN_CONFIG_CHANGE;
      arrayOfCommand[8] = FRAME_COUNT_GET;
//      ENUM$VALUES = arrayOfCommand;
     	 }
    
  }
}

/* Location:           C:\Users\Chris\Desktop\viewfinder\com.samsung.app-34_dex2jar.jar
 * Qualified Name:     com.samsungimaging.asphodel.multimedia.FFmpegJNI
 * JD-Core Version:    0.6.0
 */